<?php

namespace app\common\model;

use think\Model;

class Admin extends Model
{
    // 数据表名称
    //**不论什么时候 加上表前缀**
    protected $table = 'user';
    // 数据表主键 复合主键使用数组定义 不设置则自动获取
    protected $pk = 'uid';

    public function add($data){
        $data['password'] = md5($data['password']);
        //验证器验证
        $result = $this->validate(true)->save($data);
        if(false === $result){
            return ['valid'=>0,'msg'=>$this->getError()];
        }else{
            return ['valid'=>1,'msg'=>'添加成功'];
        }
    }

    public function edit($uid){
        //验证器验证
        $result = $this->validate(true)-$this->save();
        if(false === $result){
            return ['valid'=>0,'msg'=>$this->getError()];
        }else{
            return ['valid'=>1,'msg'=>'编辑成功'];
        }
    }
}
